IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spTsetup_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spTsetup_RetrieveAll'
		DROP  Procedure  spTsetup_RetrieveAll
	END

GO

PRINT 'Creating Procedure spTsetup_RetrieveAll'
GO

CREATE Procedure spTsetup_RetrieveAll
	(
		@PICKLIMIT decimal = null, 
		@MAXDAYS decimal = null, 
		@MAXREQ decimal = null, 
		@SENDMAIL numeric = null, 
		@SMTPIP char(16) = null, 
		@SENDEREMAIL char(40) = null, 
		@SENDERNAME char(40) = null, 
		@SENDSTSERR numeric = null, 
		@SENDSTSTO char(80) = null, 
		@RETWARN numeric = null, 
		@PICKFOLDER decimal = null, 
		@QCLETBODY text = null, 
		@ORDERNO int = null, 
		@ORDERTOEMAIL char(40) = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 8/29/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Tsetup
	
	WHERE	(@PICKLIMIT IS NULL OR Tsetup.PICKLIMIT = @PICKLIMIT)
	  AND	(@MAXDAYS IS NULL OR Tsetup.MAXDAYS = @MAXDAYS)
	  AND	(@MAXREQ IS NULL OR Tsetup.MAXREQ = @MAXREQ)
	  AND	(@SENDMAIL IS NULL OR Tsetup.SENDMAIL = @SENDMAIL)
	  AND	(@SMTPIP IS NULL OR Tsetup.SMTPIP = @SMTPIP)
	  AND	(@SENDEREMAIL IS NULL OR Tsetup.SENDEREMAIL = @SENDEREMAIL)
	  AND	(@SENDERNAME IS NULL OR Tsetup.SENDERNAME = @SENDERNAME)
	  AND	(@SENDSTSERR IS NULL OR Tsetup.SENDSTSERR = @SENDSTSERR)
	  AND	(@SENDSTSTO IS NULL OR Tsetup.SENDSTSTO = @SENDSTSTO)
	  AND	(@RETWARN IS NULL OR Tsetup.RETWARN = @RETWARN)
	  AND	(@PICKFOLDER IS NULL OR Tsetup.PICKFOLDER = @PICKFOLDER)
	  --AND	(@QCLETBODY IS NULL OR Tsetup.QCLETBODY = @QCLETBODY)
	  AND	(@ORDERNO IS NULL OR Tsetup.ORDERNO = @ORDERNO)
	  AND	(@ORDERTOEMAIL IS NULL OR Tsetup.ORDERTOEMAIL = @ORDERTOEMAIL)

	-- Return to calling method
	RETURN
GO
